/**
 * Created by zeopean on 2015/10/16.
 */
var page = 1 ;

$(function(){
    /** 初始化ajax */
    jQuery.ajaxSetup({
        case:false,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(document).on('click' ,'.more_bar' , function(){
        var stop = true;
        if(stop==true){
            stop=false;

            $.ajax({
                type:"get",
                url :getMore,
                dataType:"json",
                data:{'page':page},
                success:function(obj){
                    setTimeout(function(){
                        if (obj.level == "success") {
                            showMore(obj.data);
                        }
                    },500);
                    stop = true;
                    page = page + 1;
                }
            });
        }
    });
});


function showMore(investOrgs) {
    var HtmlAll='';
    for (var i = 0; i < investOrgs.length; i++) {
        if (investOrgs[i] !== 'undefined') {
            if(!investOrgs[i].invest_desc)
                investOrgs[i].invest_desc = '' ;
            if(!investOrgs[i].invest_name)
                investOrgs[i].invest_name = '' ;

            var HTMLInitData = '<li><dl><dt><a href="'+getDetailById+investOrgs[i].id+'"><img src="'+showPhoto+investOrgs[i].id+'" /></a><p>'
                +'</dt><dd class="commpany"><p><a href="#"><strong>'
                +investOrgs[i].invest_name
                +'</strong></a></p>'
                +investOrgs[i].invest_desc
                +'</p></dd><dd class="list"><div class="list_content"><p class="stage"><em class="reveal">投资阶段</em><em class="floatR">';
            var PhasesStr = '' ;
            if(phases = investOrgs[i].phases){
                for(var m in phases){
                    PhasesStr += phases[m];
                }
            }else{
                PhasesStr = '暂无数据';
            }

            HTMLInitData += PhasesStr + '</em></p><p class="type"><em class="reveal">机构成员</em><em class="floatR">' ;
            var membersStr = '' ;
            if(members = investOrgs[i].members){
                for(var f in members){
                    if(members[f].realname)
                        membersStr += members[f].realname;
                }
            }

            HTMLInitData += membersStr+'</em></p><p class="address"><em class="reveal">投资案例</em><em  class="floatR">' ;
            var projectsStr = '' ;
            if(projects = investOrgs[i].projects){
                for(var n in projects){
                    projectsStr += projects[n] + '&nbsp;';
                }
            }
            HTMLInitData += projectsStr+'</em></p><p class="member"><button class="reveal" data="'+investOrgs[i].id+'">提交项目</button></p>'
            +'</div></dd></dl></li>';

        }
        HtmlAll += HTMLInitData;
    }

    var onceStr = $(".content ul").html();
    $(".content ul").html(onceStr+HtmlAll);
}

function init(){}